package com.yihu.wlyy.interceptors;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerInterceptor;

import com.yihu.wlyy.repository.TokenDao;

abstract public class BaseInterceptor implements HandlerInterceptor {

	@Autowired
	public TokenDao tokenDao;

	public JSONObject getAgent(HttpServletRequest request) {
		try {
			String userAgent = request.getHeader("userAgent");
			if (StringUtils.isEmpty(userAgent)) {
				userAgent = request.getHeader("User-Agent");
			}
			System.out.println("userAgent:" + userAgent);
			return new JSONObject(userAgent);
		} catch (Exception e) {
			return null;
		}
	}

	public String error(int code, String msg) {
		try {
			JSONObject json = new JSONObject();
			json.put("status", code);
			json.put("msg", msg);
			return json.toString();
		} catch (Exception e) {
			return null;
		}
	}

}